using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;

namespace StudentManagementApplication
{
    public partial class FrmListOfAttendanceReport : Form
    {
        List<Entities.Class> classList = new List<Entities.Class>();
        List<Entities.Subject> subjectList = new List<Entities.Subject>();
        Business.ClassService classService = new Business.ClassService();
        Business.SubjectService subjectService = new Business.SubjectService();
        report rpt = null;
        string sClassID = string.Empty;
        string sSubjectID = string.Empty;

        public FrmListOfAttendanceReport()
        {
            InitializeComponent();
        }

        private void InitializeClass()
        {
            classList = classService.GetAllClasses();
            foreach (Entities.Class _class in classList)
            {
                cmbClass.Items.Add(_class.ClassID + "--" + _class.ClassName);
            }
        }

        private void InitializeSubject()
        {
            cmbSubject.Items.Clear();
            subjectList = subjectService.GetSubjectByClassID(sClassID);
            foreach(Entities.Subject subject in subjectList)
                cmbSubject.Items.Add(subject.SubjectID + "--" + subject.SubjectName);
            cmbSubject.SelectedIndex = 0;
        }

        private void InitializeReport()
        {
            
        }

        private void ShowReport()
        {
            using (DataTable dataTable = classService.GetAllStudentsOfClass(sClassID, sSubjectID))
            {
                rpt = new report();
                rpt.SetDataSource(dataTable);
                rpt.SetParameterValue("dDate", dtpDay.Value.ToShortDateString());
                crystalReportViewer1.ReportSource = rpt;
                crystalReportViewer1.Refresh();
            }
        }

        private void FrmReport_Load(object sender, EventArgs e)
        {
            InitializeClass();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            ShowReport();
        }

        private void cmbClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            sClassID = cmbClass.Text.Substring(0, 6);
            InitializeSubject();
            cmbSubject.Enabled = true;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            sSubjectID = cmbSubject.Text.Substring(0, 5);
        }
    }
}